/**
 * 运营管理添加员工
 */
import './index.less'
import tem from './index.html'
import $_fn from '~plugins'
class addstaffCtrl {
  constructor($scope,$rootScope,http,$ui) {
  	  console.log($scope.params)
      $scope.cancel = function () {
          $rootScope.$uiDirectiveModal.close() //关闭方法
      }
      //初始化对象
      $scope.param1={//接参
      	
      }
      $scope.param2={//传参
      	positionId:-1,
      	did:-1,
      	roleid:-2
      }
  	  //部门职位信息请求
  	  $scope.xinXi=function(){
  	  	http.post('toInsertUser.do',$scope.param1,function (data) {
				if(data.errcode==1){
					$ui.toast({
						text:data.errmsg,
						type:'succeed',
						appendTo:'.addstaff'
					})
					$scope.$apply(function(){
						$scope.param1.deptList=data.data.deptList;
						$scope.param1.positionList=data.data.positionList;
						$scope.param1.roles=data.data.roles;
					})
				}else{
					$ui.toast({
						text:data.errmsg,
						type:'warning',
						appendTo:'.addstaff'
					})
				}
	        },function(_data){
	            console.log(_data);//报错
	      	})
  	  }
  	  
  	  $scope.xinXi()
  	  
  	//添加管理员提交
  	  $scope.tiJiao1=function(){
	  	  	/*if(!$scope.param1.content){
	  	  		$ui.toast({
					text:'请输入备注',
					type:'warning',
					appendTo:'.addstaff'
				})
	  	  		return 
	  	  	}*/
  	  		http.post('insertUser.do',$scope.param2,function (data) {
				if(data.errcode==1){
					$ui.toast({
						text:data.errmsg,
						type:'succeed'
					})
					$scope.cancel();//返回跟踪日志弹窗
			        window.history.go(0)
				}else{
					$ui.toast({
						text:data.errmsg,
						type:'warning',
						appendTo:'.addstaff'
					})
				}
	        },function(_data){
	            console.log(_data);//报错
	      	})
  	  }
  }
}
addstaffCtrl.$inject = ['$scope','$rootScope','http','$ui']
module.exports = angular.module('directive.addstaff', []).directive('addstaff', function() {
    return {
        template: tem,
        replace:true,
        controller: addstaffCtrl,
        scope:{
        	params:"@"
        }
    }
}).name